{% extends "base.html" %}
{% load humanize %}

{% block content %}
{% if no_results %}
 <h2>No results matched your search.</h2>
{% else %}
 {% if page.object_list %}
  <div class="ads">
  {% for ad in page.object_list %}
   <div class="ad{% if forloop.first %} first{% endif %}">
    <div class="description">
    {% if ad.adimage_set.all.0 %}
     <img src="{{ ad.adimage_set.all.0.get_thumb_photo_url }}" alt="Photo Thumbnail" width="50" height="30" />
    {% else %}
     <img src="{{ MEDIA_URL }}images/none.jpeg" alt="No Photo" width="50" height="30" />
    {% endif %}
     <div class="right">
      <div class="title">{{ ad.title }}</div>
      {% if ad.fields_dict.price %}
      <span class="price">${{ ad.fields_dict.price|intcomma }}</span>&nbsp;|&nbsp;{% endif %}<a href="{% url adposting.views.view ad.pk %}">View</a>
      
     </div>
    </div>
   {% ifequal ad.user user %}
    <div class="options">
     <span class="label">Ad ID : </span>{{ ad.pk }}&nbsp;|&nbsp;{{ ad.adimage_set.count }} Photos&nbsp;|&nbsp;<a href="{% url adposting.views.view ad.pk %}">View Details</a>&nbsp;|&nbsp;<a href="{% url adposting.views.edit ad.pk %}">Edit Listing</a>&nbsp;|&nbsp;<a onclick="return confirm('Are you sure you want to delete this ad?');" href="{% url adposting.views.delete ad.pk %}">Delete Listing</a>&nbsp;|&nbsp;<a href="{% url payment.views.checkout ad.pk %}">Renew Listing</a>
    </div>
   {% endifequal %}
   </div>
  {% endfor %}
  </div>
 
  {% include "pager.html" %} 
 {% else %}
  <p>You don't have any ads. Post a new ad <a href="{% url adposting.views.create %}">here</a>.
 {% endif %}
{% endif %}
{% endblock %}


